import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:fucius/splash.dart';
import 'package:fucius/widgets/chat_page.dart';
import 'package:fucius/widgets/job_page.dart';
import 'package:fucius/widgets/login/authentication.dart';
import 'package:fucius/widgets/login/root_page.dart';
import 'package:fucius/widgets/mine_page.dart';
import 'package:fucius/widgets/talent_page.dart';
import 'package:redux/redux.dart';


void main() {
  runApp(new MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
        title: 'Flutter login demo',
        debugShowCheckedModeBanner: false,
        theme: new ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: new RootPage(auth: new Auth()));
  }
}

abstract class HasLayoutGroup {
  VoidCallback get onLayoutToggle;
}

enum LayoutType {
  job,
  talent,
  chat,
  mine,
}

String layoutName(LayoutType layoutType) {
  switch (layoutType) {
    case LayoutType.job:
      return 'Job';
    case LayoutType.talent:
      return 'Talent';
    case LayoutType.chat:
      return 'Chat';
    case LayoutType.mine:
      return 'Mine';
    default:
      return '';
  }
}

class App extends StatelessWidget {
  final Store<int> store;
  final String title;


  App({Key key, this.store, this.title}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      theme: new ThemeData(
        primaryIconTheme: const IconThemeData(color: Color(0xfffcfcff)),
        brightness: Brightness.light,
        primaryColor: Color(0xfffcfcff),
        accentColor: Colors.cyan[300],
      ),
      home: SplashPage(),
    );
  }
}

class MainPage extends StatefulWidget {

  MainPage({Key key, this.auth, this.userId, this.logoutCallback})
      : super(key: key);

  final BaseAuth auth;
  final VoidCallback logoutCallback;
  final String userId;


  @override
  _MainPageState createState() => new _MainPageState();
}

class _MainPageState extends State<MainPage> {
  LayoutType _layoutSelection = LayoutType.job;

  Color _colorTabMatching({LayoutType layoutSelection}) {
    return _layoutSelection == layoutSelection ? Colors.blue : Colors.grey;
  }

  BottomNavigationBarItem _buildItem(
      {Icon icon, LayoutType layoutSelection}) {
    String text = layoutName(layoutSelection);
    return BottomNavigationBarItem(
      icon: Icon(icon.icon, color: Colors.blue,),
      title: Text(
        text,
        style: TextStyle(
          color: _colorTabMatching(layoutSelection: layoutSelection),
        ),
      ),
    );
  }

  Widget _buildButtonNavBar() {
    return BottomNavigationBar(
      type: BottomNavigationBarType.fixed,
      items: [
        _buildItem(
            icon: Icon(Icons.home),
            layoutSelection: LayoutType.job),
        _buildItem(
            icon: Icon(Icons.business),
            layoutSelection: LayoutType.talent),
        _buildItem(
            icon: Icon(Icons.chat),
            layoutSelection: LayoutType.chat),
        _buildItem(
            icon: Icon(Icons.school),
            layoutSelection: LayoutType.mine),
      ],
      onTap: _onSelectTab,
    );
  }

  void _onLayoutSelected(LayoutType selection) {
    setState(() {
      _layoutSelection = selection;
    });
  }

  void _onSelectTab(int index) {
    switch (index) {
      case 0:
        _onLayoutSelected(LayoutType.job);
        break;
      case 1:
        _onLayoutSelected(LayoutType.talent);
        break;
      case 2:
        _onLayoutSelected(LayoutType.chat);
        break;
      case 3:
        _onLayoutSelected(LayoutType.mine);
        break;
    }
  }

  Widget _buildBody() {
    LayoutType layoutTypeSelection = _layoutSelection;
    switch (layoutTypeSelection) {
      case LayoutType.job:
        return JobPage();
      case LayoutType.talent:
        return TalentPage(auth: this.widget.auth,);
      case LayoutType.chat:
        return ChatPage(currentUserId: widget.userId,);
      case LayoutType.mine:
        return MinePage(userId: this.widget.userId,
            auth: this.widget.auth,
            logoutCallback: this.widget.logoutCallback);
    }
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: _buildBody(),
      bottomNavigationBar: _buildButtonNavBar(),
    );
  }
}










